package tt.dz.egobus.servicemanager.vo;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.servicemanager.bean.EntityViewVo;
import tt.dz.egobus.servicemanager.entities.BusService;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;

/**
 * @author Anson
 * @date 17-8-25
 * @name 司机服务Vo
 * @since 1.0.6
 */
public class BusServiceViewVo implements EntityViewVo<BusService, BusServiceViewVo> {
    private static final long serialVersionUID = 4411127510333923216L;

    private static final Logger LOGGER = LoggerFactory.getLogger(BusServiceViewVo.class);


    @Override
    public BusService convert() {
        BusService pojo = new BusService();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("BusServiceVo -> BusService bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    @Override
    public BusServiceViewVo view(BusService pojo) {
        if (pojo == null) {
            return this;
        }
        try {
            BeanUtils.copyProperties(pojo, this);
        } catch (BeansException e) {
            LOGGER.error("BusService  -> BusServiceViewVo bean拷贝异常, viewVo={}", this, e);
        }
        return this;
    }

    private String id;

    /**
     * 服务名称
     */
    @NotBlank(message = "服务名称不能为空")
    @Length(max = 50, message = "服务名称长度不能超过50")
    private String name;

    /**
     * 基础费用
     */
    @NotNull(message = "基础费用不能为空")
    @Max(value = 1000000, message = "系统允许的最大基础费用不能超过1百万元")
    private double basicsCost;

    /**
     * 时间限制，单位分
     */
    @NotNull(message = "时间限制不能为空")
    @Max(value = 7 * 24 * 60, message = "系统允许的最大时间限制不能超过一周时间间隔")
    private int timeLimit;
    /**
     * 里程限制，单位米
     */
    @NotNull(message = "里程限制不能为空")
    @Max(value = 1000000, message = "系统允许的最大距离不能超过1000千米")
    private double milesLimit;

    /**
     * 超时计价时间单位：分
     */
    @NotNull(message = "超时计价时间单位不能为空")
    @Max(value = 525600, message = "系统允许的超时计价时间不能超过一年时间间隔")
    private int timeUnit;

    /**
     * 超时计价价格单位：元
     */
    @NotNull(message = "超时计价价格单位不能为空")
    @Max(value = 1000000, message = "系统允许的超时计价价格不能超过百万")
    private double priceUnit;


    /**
     * 是否激活
     */
    private boolean isActive = false;

    /**
     * 服务号来自订单系统
     * 一种服务，有且仅有一种服务号对应
     */
    private int businessCode;

    /**
     * 服务说明
     */
    private String serviceRemark;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getBasicsCost() {
        return basicsCost;
    }

    public void setBasicsCost(double basicsCost) {
        this.basicsCost = basicsCost;
    }

    public int getTimeLimit() {
        return timeLimit;
    }

    public void setTimeLimit(int timeLimit) {
        this.timeLimit = timeLimit;
    }

    public double getMilesLimit() {
        return milesLimit;
    }

    public void setMilesLimit(double milesLimit) {
        this.milesLimit = milesLimit;
    }

    public int getTimeUnit() {
        return timeUnit;
    }

    public void setTimeUnit(int timeUnit) {
        this.timeUnit = timeUnit;
    }

    public double getPriceUnit() {
        return priceUnit;
    }

    public void setPriceUnit(double priceUnit) {
        this.priceUnit = priceUnit;
    }

    public void setIsActive(boolean active) {
        isActive = active;
    }

    public boolean getIsActive() {
        return isActive;
    }

    public int getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(int businessCode) {
        this.businessCode = businessCode;
    }


    public String getServiceRemark() {
        return serviceRemark;
    }

    public void setServiceRemark(String serviceRemark) {
        this.serviceRemark = serviceRemark;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BusServiceViewVo that = (BusServiceViewVo) o;

        if (Double.compare(that.basicsCost, basicsCost) != 0) return false;
        if (timeLimit != that.timeLimit) return false;
        if (Double.compare(that.milesLimit, milesLimit) != 0) return false;
        if (timeUnit != that.timeUnit) return false;
        if (Double.compare(that.priceUnit, priceUnit) != 0) return false;
        if (isActive != that.isActive) return false;
        if (businessCode != that.businessCode) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        return serviceRemark != null ? serviceRemark.equals(that.serviceRemark) : that.serviceRemark == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        temp = Double.doubleToLongBits(basicsCost);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + timeLimit;
        temp = Double.doubleToLongBits(milesLimit);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + timeUnit;
        temp = Double.doubleToLongBits(priceUnit);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (isActive ? 1 : 0);
        result = 31 * result + businessCode;
        result = 31 * result + (serviceRemark != null ? serviceRemark.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "BusServiceViewVo{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", basicsCost=" + basicsCost +
                ", timeLimit=" + timeLimit + ", milesLimit=" + milesLimit + ", timeUnit=" + timeUnit + ", priceUnit="
                + priceUnit + ", isActive=" + isActive + ", businessCode=" + businessCode + ", serviceRemark='" +
                serviceRemark + '\'' + '}';
    }
}
